package com.aaa.three.service.impl;

import com.aaa.three.mapper.NewsColumnMapper;
import com.aaa.three.pojo.domain.NewsColumn;
import com.aaa.three.pojo.domain.NewsColumnTwo;
import com.aaa.three.pojo.query.NewsColumnQuery;
import com.aaa.three.pojo.vo.NewsColumnVO;
import com.aaa.three.result.AjaxResult;
import com.aaa.three.service.NewsColumnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.HashMap;
import java.util.List;

/**
 * @Description:
 * @Author: whf
 * @Date: 2022/2/14 19:56
 */
@Service
public class NewsColumnServiceImpl implements NewsColumnService {

    @Autowired
    private NewsColumnMapper newsColumnMapper;

    @Override
    public AjaxResult listColumn(NewsColumnQuery newsColumnQuery) {
        List<NewsColumn> columns = newsColumnMapper.listAll(newsColumnQuery);
        Long aLong = newsColumnMapper.queryNewsColumnTotal(newsColumnQuery);
        HashMap<Object, Object> map = new HashMap<>();
        map.put("currentData", columns);
        map.put("totalCount", aLong);
        return AjaxResult.success(map);
    }

    @Override
    public AjaxResult addColumn(NewsColumnVO newsColumnVO) {
        int i = newsColumnMapper.addColumn(newsColumnVO);
        System.out.println(newsColumnVO);
        if (i > 0) {
            return AjaxResult.success();
        }
        return AjaxResult.fail("添加失败");
    }

    @Override
    public AjaxResult deleteColumn(Integer id) {
        int i = newsColumnMapper.deleteColumn(id);
        if (i > 0) {
            return AjaxResult.success();
        }
        return AjaxResult.fail("删除失败");
    }

    @Override
    public AjaxResult getColumn(Integer id) {
        NewsColumnVO newsColumnVO = newsColumnMapper.getColumnById(id);
        return AjaxResult.success(newsColumnVO);
    }

    @Override
    public AjaxResult updateColumn(NewsColumnVO newsColumnVO) {
        int i = newsColumnMapper.updateColumn(newsColumnVO);
        if (i > 0) {
            return AjaxResult.success();
        }
        return AjaxResult.fail("失败");
    }

    @Override
    public AjaxResult newsListNewsColumn() {
        List<NewsColumnTwo> newsColumns = newsColumnMapper.newsListNewsColumn();
        return AjaxResult.success(newsColumns);
    }


}
